#ifndef									__TCPSERVER_H__
#define									__TCPSERVER_H__

#include								"async.h"
#include								"TcpSocket.h"
#include								"handler.h"
#include								"packet.h"

class									TcpServer
{
public:
	TcpServer(Async&, PacketHandler*);
	~TcpServer();

private:
	boost::asio::ip::tcp::acceptor		_acceptor;
	std::map<unsigned int, TcpSocket::SocketPtr>	_sockets;
	PacketHandler						*_handler;
	unsigned int						_current_id;

public:
	void								start();
	void								sendPacket(Packet* , unsigned int);
	unsigned int						getId(std::string);
	std::string							getIp(unsigned int);
	void								closeSocket(unsigned int);
	bool								isOpen(unsigned int);

private:
	void								_start_accept();
	void								_handle_accept(TcpSocket::SocketPtr, const boost::system::error_code &);
};

#endif // !__TCPSERVER_H__
